<%@ page import="java.util.jar.Attributes.Name"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1" import="support.*, java.util.*" %>
    
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Residence</title>
<link href="main.css" rel="stylesheet" type="text/css">


</head>
<body>
<%
	// Get citizenship from HTTP request
	String country = request.getParameter("citizenship");
	String countryID = request.getParameter("citizenshipID");

	Applicant a = (Applicant) session.getAttribute("applicant");
	a.setCitizenship(new Country(Integer.valueOf(countryID), country));
	
	// Store applicant in session
	session.setAttribute("applicant", a);
	
	// Get countries from database
	DatabaseAccessObject dao = new DatabaseAccessObject();
//	dao.connect();
	LinkedList<Country> countries = dao.getCountries();
//	dao.close();
	
%>

<jsp:include page="information.jsp"></jsp:include>

<h1>Please choose your residence</h1>
<a href="address.jsp?residenceID=<%= countryID %>&residence=<%= country %>" >Same with citizenship</a><br /><br />
<table class="multicolumn">
	<tr>
		<% 
		int cols = 3;
		int itemsPerCol = countries.size() / cols;
		if (countries.size() % cols != 0) itemsPerCol += 1;
		
		for(int i=0; i<countries.size(); i++){
			if (i % itemsPerCol == 0)  out.println("<td>");
			out.println("<a class=\"list\" href=\"address.jsp?residenceID=" + countries.get(i).getId() + 
					              "&residence=" + countries.get(i).getName() + "\" >" + 
			                      countries.get(i).getName() + "</a>");
			if (i % itemsPerCol == itemsPerCol-1 || i==countries.size() -1 )  out.println("</td>");
		};
		%>
	</tr>
</table>

</body>
</html>